package reflex;

import java.io.InputStream;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.util.Properties;

/**
 * @author Yancy
 * @program springioctest
 * @create 2021-01-16
 */
public class ReflectDemo {

  public static void main(String[] args) throws Exception {
    //

    Properties pro = new Properties();
    // 使用ClassLoader加载pro.properties配置文件
    ClassLoader classLoader = ReflectDemo.class.getClassLoader();
    InputStream in = classLoader.getResourceAsStream("pro.properties");
    pro.load(in);
    String className = pro.getProperty("className");

    Class classPerson = Class.forName(className);
    //    Object person = classPerson.newInstance();
    Constructor c = classPerson.getConstructor(String.class, int.class);
    Object person = c.newInstance("张三", 22);
    System.out.println(person);


      String methodName = pro.getProperty("methodName");
      Method method = classPerson.getMethod(methodName);

      method.invoke(person);
  }
}
